package com.iflytek.yousheng;

import com.alibaba.fastjson.JSONObject;
import com.iflytek.yousheng.Util.OkHttp3Utils;
import com.iflytek.yousheng.Util.SginUtils;

import java.io.IOException;
import java.util.UUID;

public class Get {

    private final static String url = "https://newserver.xfyousheng.com/";

    private final static String querypath = "api/v1/vir/get";
    private final static String appId = "xxxxxxxxx";//替换授权的appid
    private final static String appKey = "xxxxxxxxxxxxxxxxxxxxxxx";//替换对于的appkey
    public static void main(String[] args) {
        String requrl = String.format("%s%s",url,querypath);
        JSONObject req = new JSONObject();

        JSONObject base = new JSONObject();
        base.put("appid", appId);
        base.put("sid", UUID.randomUUID().toString());
        base.put("timestamp", System.currentTimeMillis());

        JSONObject param = new JSONObject();
        param.put("taskId", "a45914e4-d673-46e4-bdb7-c3536e6fedc1");

        req.put("base",base);
        req.put("param",param);

        String sign = SginUtils.buildSign(req, appKey);
        System.out.println("sign:"+sign);
        base.put("sign", sign);


        String reqString = req.toJSONString();
        System.out.printf("请求体:%s \n", reqString);

        String respBody = "";
        try {
            respBody = OkHttp3Utils.postJson(requrl, reqString);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.printf("返回结果:%s \n", respBody);
    }
}
